Imports System.Reflection

Imports Phoenix.reportengine

Namespace Forms.Dialogs

    Public Class ReportsForm : Inherits PhoenixFormBase

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents btnEODReport As DevExpress.XtraEditors.SimpleButton
        Friend WithEvents FromDateEdit As DevExpress.XtraEditors.DateEdit
        Friend WithEvents ToDateEdit As DevExpress.XtraEditors.DateEdit
        Friend WithEvents ReportTypeCombo As DevExpress.XtraEditors.ComboBoxEdit
        Friend WithEvents SaveReportDialog As System.Windows.Forms.SaveFileDialog
        Friend WithEvents ReportLabel As System.Windows.Forms.Label
        Friend WithEvents FromLabel As System.Windows.Forms.Label
        Friend WithEvents ToLabel As System.Windows.Forms.Label
        Friend WithEvents CancelBtn As DevExpress.XtraEditors.SimpleButton
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ReportsForm))
            Me.btnEODReport = New DevExpress.XtraEditors.SimpleButton
            Me.FromDateEdit = New DevExpress.XtraEditors.DateEdit
            Me.ToDateEdit = New DevExpress.XtraEditors.DateEdit
            Me.ReportTypeCombo = New DevExpress.XtraEditors.ComboBoxEdit
            Me.ReportLabel = New System.Windows.Forms.Label
            Me.FromLabel = New System.Windows.Forms.Label
            Me.ToLabel = New System.Windows.Forms.Label
            Me.SaveReportDialog = New System.Windows.Forms.SaveFileDialog
            Me.CancelBtn = New DevExpress.XtraEditors.SimpleButton
            CType(Me.FromDateEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ToDateEdit.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ReportTypeCombo.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'btnEODReport
            '
            Me.btnEODReport.Location = New System.Drawing.Point(152, 104)
            Me.btnEODReport.Name = "btnEODReport"
            Me.btnEODReport.Size = New System.Drawing.Size(80, 23)
            Me.btnEODReport.TabIndex = 6
            Me.btnEODReport.Text = "&OK"
            '
            'FromDateEdit
            '
            Me.FromDateEdit.EditValue = New Date(2005, 4, 6, 0, 0, 0, 0)
            Me.FromDateEdit.Location = New System.Drawing.Point(88, 40)
            Me.FromDateEdit.Name = "FromDateEdit"
            '
            'FromDateEdit.Properties
            '
            Me.FromDateEdit.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.FromDateEdit.Size = New System.Drawing.Size(232, 20)
            Me.FromDateEdit.TabIndex = 3
            '
            'ToDateEdit
            '
            Me.ToDateEdit.EditValue = New Date(2005, 4, 6, 0, 0, 0, 0)
            Me.ToDateEdit.Location = New System.Drawing.Point(88, 72)
            Me.ToDateEdit.Name = "ToDateEdit"
            '
            'ToDateEdit.Properties
            '
            Me.ToDateEdit.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ToDateEdit.Size = New System.Drawing.Size(232, 20)
            Me.ToDateEdit.TabIndex = 5
            Me.ToDateEdit.Visible = False
            '
            'ReportTypeCombo
            '
            Me.ReportTypeCombo.EditValue = "End Of Day Report"
            Me.ReportTypeCombo.Location = New System.Drawing.Point(88, 8)
            Me.ReportTypeCombo.Name = "ReportTypeCombo"
            '
            'ReportTypeCombo.Properties
            '
            Me.ReportTypeCombo.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ReportTypeCombo.Properties.Items.AddRange(New Object() {"End Of Day Report", "Quick Salon Report", "Full Salon Report"})
            Me.ReportTypeCombo.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor
            Me.ReportTypeCombo.Size = New System.Drawing.Size(232, 20)
            Me.ReportTypeCombo.TabIndex = 1
            '
            'ReportLabel
            '
            Me.ReportLabel.Location = New System.Drawing.Point(8, 10)
            Me.ReportLabel.Name = "ReportLabel"
            Me.ReportLabel.Size = New System.Drawing.Size(80, 16)
            Me.ReportLabel.TabIndex = 0
            Me.ReportLabel.Text = "&Report Type:"
            '
            'FromLabel
            '
            Me.FromLabel.Location = New System.Drawing.Point(8, 42)
            Me.FromLabel.Name = "FromLabel"
            Me.FromLabel.Size = New System.Drawing.Size(40, 16)
            Me.FromLabel.TabIndex = 2
            Me.FromLabel.Text = "&From:"
            '
            'ToLabel
            '
            Me.ToLabel.Location = New System.Drawing.Point(8, 74)
            Me.ToLabel.Name = "ToLabel"
            Me.ToLabel.Size = New System.Drawing.Size(40, 16)
            Me.ToLabel.TabIndex = 4
            Me.ToLabel.Text = "&To:"
            Me.ToLabel.Visible = False
            '
            'SaveReportDialog
            '
            Me.SaveReportDialog.Filter = "MS Excel files (*.xls)|*.xls|All files (*.*)|*.*"
            Me.SaveReportDialog.Title = "Save Report As:"
            '
            'CancelBtn
            '
            Me.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.CancelBtn.Location = New System.Drawing.Point(240, 104)
            Me.CancelBtn.Name = "CancelBtn"
            Me.CancelBtn.Size = New System.Drawing.Size(80, 23)
            Me.CancelBtn.TabIndex = 7
            Me.CancelBtn.Text = "&Cancel"
            '
            'ReportsForm
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.CancelButton = Me.CancelBtn
            Me.ClientSize = New System.Drawing.Size(330, 136)
            Me.Controls.Add(Me.CancelBtn)
            Me.Controls.Add(Me.ToLabel)
            Me.Controls.Add(Me.FromLabel)
            Me.Controls.Add(Me.ReportLabel)
            Me.Controls.Add(Me.ReportTypeCombo)
            Me.Controls.Add(Me.ToDateEdit)
            Me.Controls.Add(Me.FromDateEdit)
            Me.Controls.Add(Me.btnEODReport)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
            Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "ReportsForm"
            Me.ShowInTaskbar = False
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
            Me.Text = "Reports"
            CType(Me.FromDateEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ToDateEdit.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ReportTypeCombo.Properties, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region " Event Handers "
        Private Sub ReportsForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            FromDateEdit.DateTime = Now
            ToDateEdit.DateTime = FromDateEdit.DateTime
        End Sub

        Private Sub ReportTypeCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ReportTypeCombo.SelectedIndexChanged
            Dim fl As Boolean = False

            If ReportTypeCombo.SelectedIndex = 0 Then
                fl = False
            Else
                fl = True
            End If

            ToDateEdit.Visible = fl
            ToLabel.Visible = fl
        End Sub

        Private Sub btnEODReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEODReport.Click
            Dim path As String

            Select Case (ReportTypeCombo.SelectedIndex)
                Case 0
                    path = "End Of Day Report ({0:MM-dd-yyyy}).xls"
                Case 1
                    path = "Quick Salon Report ({0:MM-dd-yyyy} - {1:MM-dd-yyyy}).xls"
                Case 2
                    path = "Full Salon Report ({0:MM-dd-yyyy} - {1:MM-dd-yyyy}).xls"
            End Select

            SaveReportDialog.FileName = String.Format(path, FromDateEdit.DateTime, ToDateEdit.DateTime)

            If SaveReportDialog.ShowDialog() <> DialogResult.OK Then Exit Sub

            Close()
            Application.DoEvents()

            Dim sd As Date = FromDateEdit.DateTime.Date
            Dim ed As Date = ToDateEdit.DateTime.Date.AddHours(23).AddMinutes(59).AddSeconds(59)

            Select Case (ReportTypeCombo.SelectedIndex)
                Case 0
                    Helpers.ReportHelper.GenerateEndOfDayReport(sd, SaveReportDialog.FileName)
                Case 1
                    Helpers.ReportHelper.GenerateQuickSalonReport(sd, ed, SaveReportDialog.FileName)
                Case 2
                    Helpers.ReportHelper.GenerateFullSalonReport(sd, ed, SaveReportDialog.FileName)
            End Select
        End Sub

        Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelBtn.Click
            Close()
        End Sub
#End Region

    End Class
End Namespace
